package com.handinfo.android.uicontrols;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class DWCharsDetection {
	/**
	 * 检测是否为邮箱
	 * @param str
	 * @return
	 */
	public static boolean detectionMail(String str) {
		if (str != null) {
			Pattern pattern = Pattern.compile(MAIL, Pattern.CASE_INSENSITIVE);
			Matcher matcher = pattern.matcher(str);
			return matcher.matches();
		}
		return false;
	}
	/**
	 * 检测是否为字母和数字
	 * @param str
	 * @return
	 */
	public static boolean detectionLetterNumbers(String str) {
		if (str != null) {
			return str.matches(LETTER_NUMBERS);
		}
		return false;
	}
	
	/**
	 * 检测是否为字母
	 * @param str
	 * @return
	 */
	public static boolean detectionLetter(String str) {
		if (str != null) {
			return str.matches(LETTER);
		}
		return false;
	}
	
	/**
	 * 检测是否为数字
	 * @param str
	 * @return
	 */
	public static boolean detectionNumbers(String str) {
		if (str != null) {
			return str.matches(NUMBERS);
		}
		return false;
	}
	
	/**
	 * 检测是否有特殊符号
	 * @param str
	 * @return
	 */
	public static boolean detectionSpecific(String str) {
		if (str != null) {
			return str.matches(SPECIFIC);
		}
		return false;
	}
	
	/**
	 * 检测是否为大写字母
	 * @param str
	 * @return
	 */
	public static boolean detectionCapitalLetter(String str) {
		if (str != null) {
			return str.matches(CAPITAL_LETTER);
		}
		return false;
	}
	
	/**
	 * 检测是否为小写字母
	 * @param str
	 * @return
	 */
	public static boolean detectionLowerLetter(String str) {
		if (str != null) {
			return str.matches(LOWER_LETTER);
		}
		return false;
	}
	private static final String LOWER_LETTER = "^[a-z]+$";
	private static final String CAPITAL_LETTER = "^[A-Z]+$";
	private static final String NUMBERS = "^[0-9]+$";
	private static final String LETTER = "^[a-zA-Z]+$";
	private static final String LETTER_NUMBERS = "^[a-zA-Z0-9]+$";
	private static final String MAIL = "[\\w\\.\\-]+@([\\w\\-]+\\.)+[\\w\\-]+";
//	private static final String SPECIFIC = "[`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~！@#￥%……& amp;*（）——+|{}【】‘；：”“’。，、？]";
	private static final String SPECIFIC = "[`~#$%^&*()+=|{}':;'\\[\\]<>/~#￥%……& ;*（）——+|{}【】‘；：”“’、]";
//	private static final String PUNCTUATION = "[.,?!。，？！]";
	
	public static final byte CHARS_TYPE_ALL = 0;
	public static final byte CHARS_TYPE_LETTER = 1;
	public static final byte CHARS_TYPE_NUMBERS = 2;
	public static final byte CHARS_TYPE_MAIL = 3;
	public static final byte CHARS_TYPE_NO_SPECIFIC = 4;
	public static final byte CHARS_TYPE_LETTER_NUMBERS = 5;
//	public static final int CHARS_TYPE_ = 1 << 5;
//	public static final int CHARS_TYPE_ = 1 << 6;
}
